﻿@model Matrix.MaKaYunShang.Model.CloudCards

@{
    ViewBag.Title = "编辑卡券";
    ViewBag.PathToBtn = "/CloudCards/List";
    ViewBag.TextBtn = "返回至列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                卡券信息
            </div>
            <div class="panel-body">
                <div class="row">
                    @using (Html.BeginForm("Update", "CloudCards", FormMethod.Post, new { id = "frmUpdate", enctype = "multipart/form-data" }))
                    {
                        @Html.AntiForgeryToken()
                        @Html.ValidationSummary(true)
                        <div class="col-lg-12">
                            <fieldset>
                                @Html.HiddenFor(model => model.Id)
                                @Html.HiddenFor(model => model.LoGo)
                                @Html.HiddenFor(model => model.CategoryCode)
                                <input type="hidden" id="hidCanShare" value="@(Model.CanShare ? 1 : 0)" />
                                <div class="form-group col-md-12" style="display: none">
                                    <input id="fileImage" class="form-control" type="file" name="fileImage" style="display: none;" />
                                    <input id="btnSelect" type=button class="btn btn-info" value="上传列表图" onclick="fileImage.click()" />
                                    <img id="imgThumb" alt="缩略图" style="max-height: 80px" src="/Content/admin/image/uploadimg.png" imgpath="/Content/admin/image/uploadimg.png" />
                                    <span>（建议尺寸：宽180*高180，200KB以内）</span>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>卡券名称</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.CardName, new { @class = "form-control", placeholder = "卡券名称", @readonly = "readonly" })
                                        <span class="input-group-addon red">必填</span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>所属商家</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.ShopName, new { @class = "form-control", placeholder = "所属商家", @readonly = "readonly" })
                                        <span class="input-group-addon red">必填</span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>卡券类别</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.CategoryName, new { @class = "form-control", placeholder = "卡券类别", @readonly = "readonly" })
                                        <span class="input-group-addon red">必填</span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>卡券价值</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.CardValue, new { @class = "form-control", placeholder = "卡券价值", @readonly = "readonly" })
                                        <span class="input-group-addon">元</span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>开始时间</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.StartTime, new { @class = "form-control form_datetime", placeholder = "开始", Value = String.Format("{0:yyyy-MM-dd HH:mm}", Model.StartTime), @onfocus = "WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" })
                                        <span class="input-group-addon red">必填</span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>结束时间</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.EndTime, new { @class = "form-control form_datetime", placeholder = "结束", Value = String.Format("{0:yyyy-MM-dd HH:mm}", Model.EndTime), @onfocus = "WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" })
                                        <span class="input-group-addon red">必填</span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>是否可转赠</label>
                                    <div class="input-group">
                                        @Html.DropDownList("CanShare", (IEnumerable<SelectListItem>)ViewBag.CanShare, new { @class = "form-control" })
                                        <span class="input-group-addon"></span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6" id="divLeastCost" style="display: none">
                                    <label>最低消费</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.LeastCost, new { @class = "form-control", placeholder = "请填写最低消费（满额可用）", @readonly = "readonly" })
                                        <span class="input-group-addon">元</span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6" id="divReduceCost" style="display: none">
                                    <label>减免金额</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.ReduceCost, new { @class = "form-control", placeholder = "请填写减免金额", @readonly = "readonly" })
                                        <span class="input-group-addon">元</span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6" id="divDiscountValue" style="display: none">
                                    <label>折扣额度</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.DiscountValue, new { @class = "form-control", placeholder = "请填写折扣额度（填30就是七折）", @readonly = "readonly" })
                                        <span class="input-group-addon"></span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>优惠说明</label>
                                    <div class="input-group">
                                        @Html.TextAreaFor(model => model.Description, new { @class = "form-control", rows = "5", placeholder = "优惠说明", @readonly = "readonly" })
                                        <span class="input-group-addon red"></span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>使用须知</label>
                                    <div class="input-group">
                                        @Html.TextAreaFor(model => model.Instruction, new { @class = "form-control", rows = "5", placeholder = "使用须知", @readonly = "readonly" })
                                        <span class="input-group-addon red"></span>
                                    </div>
                                </div>
                                <div class="col-md-12">
                                    <button id="btnSave" type="submit" class="btn btn-primary">确定并保存</button>
                                </div>
                            </fieldset>
                        </div>
                    }
                </div>
            </div>
        </div>
    </div>
</div>

@section javascript{
    <script src="/Content/admin/dist/js/imageUploader.js"> </script>
    <script type="text/javascript">
        // Image Upload
        imageUploader.uploadSingle(fileImage, btnSelect, imgThumb, '@ViewBag.theHeadPic');

        $(function () {
            changeCardCategory();

            $("#frmUpdate").validate({
                rules: {
                    TotalQuantity: { required: true, digits: true, min: 1 },
                    StartTime: { required: true },
                    EndTime: { required: true }
                },
                messages: {
                    CommodityName: { required: "请填写卡券总数" },
                    StartTime: { required: "请选择开始时间" },
                    EndTime: { required: "请选择结束时间" }
                },
                submitHandler: function (form) {
                    showLoading();
                    $("#btnSave").html("正在保存...").attr("disabled", "disabled");
                    form.submit();
                }
            });

            var canShare = $("#hidCanShare").val();
            if (canShare == 1) {
                $("#CanShare").val("true");
            } else {
                $("#CanShare").val("false");
            }
        });

        function changeCardCategory() {
            var code = $("#CategoryCode").val();
            if (code == "1002") {
                $("#divLeastCost").show();
                $("#divReduceCost").show();
                $("#divDiscountValue").hide();
            } else if (code == "1003") {
                $("#divLeastCost").show();
                $("#divReduceCost").hide();
                $("#divDiscountValue").show();
            } else {
                $("#divLeastCost").hide();
                $("#divReduceCost").hide();
                $("#divDiscountValue").hide();
            }
        }
    </script>
}